home *** CD-ROM | disk | FTP | other *** search
/ Mac Power 1996 June / MACPOWER-1996-06.ISO.7z / MACPOWER-1996-06.ISO / AMUG / PROGRAMING_7 / Fat Module / Fat Module ト / GraphicsModule_main.c < prev    next >
C/C++ Source or Header  |  1995-08-20  |  4KB  |  129 lines

  1. /*
  2.     GraphicsModule_main.c
  3.     
  4.     Apple and Think C Implementation of 'ADgm' screen saver code resource.
  5.     
  6.     This file provides a generic interface for writing a After Darkェ graphics module.
  7.     The function "main" is called by After Dark and passed four parameters:
  8.     
  9.         storage:    A Handle to memory you have allocated.
  10.         blankRgn:    A region covering all screens.
  11.         message:    A value indicating which function to call.
  12.         params:        A pointer to a structure containing useful information.
  13.         
  14.     To use it, write the five routines:
  15.     
  16.     OSErr DoInitialize(Handle *storage, RgnHandle blankRgn, GMParamBlockPtr params);
  17.     OSErr DoClose(Handle storage, RgnHandle blankRgn, GMParamBlockPtr params);
  18.     OSErr DoBlank(Handle storage, RgnHandle blankRgn, GMParamBlockPtr params);
  19.     OSErr DoDrawFrame(Handle storage, RgnHandle blankRgn, GMParamBlockPtr params);
  20.     OSErr DoSetUp(RgnHandle blankRgn, short message, GMParamBlockPtr params);
  21.     
  22.     For more information, consult the programmer's section of the manual.
  23.     
  24.     By Patrick Beard and Bruce Burkhalter and Colin Glassey
  25.     
  26.     ゥ1989,1990,1991 Berkeley Systems, Inc.
  27.  
  28.     ------
  29.  
  30.     I added the following for use with Metrowerks C++ 1.2.2:
  31.  
  32.     -    Support for Metrowerks A4 globals.
  33.  
  34.     -    Prototypes.
  35.  
  36.     -    A __procinfo definition.
  37.  
  38.     Note that Berkeley Systems has no responsibility for this altered version of
  39.     GraphicsModule_main.c. Use it at your own risk.
  40.  
  41.     Robert Geisler, 8/20/95
  42.  
  43.  */
  44.  
  45. #include <QuickDraw.h>
  46. #include "GraphicsModule_Types.h"
  47. #ifdef THINK_C
  48. /* allows use of Global vars with Think C */
  49. #include <SetUpA4.h>
  50. #define OpenGlobals()    RememberA0(); SetUpA4();
  51. #define CloseGlobals()    RestoreA4();
  52. #endif
  53. #ifdef __MWERKS__
  54. #include <A4Stuff.h>
  55.  
  56.  
  57. ProcInfoType __procinfo=kPascalStackBased
  58.     |RESULT_SIZE(SIZE_CODE(sizeof(OSErr)))
  59.     |STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(Handle *)))
  60.     |STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(RgnHandle)))
  61.     |STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(short)))
  62.     |STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(GMParamBlockPtr)));
  63. OSErr DoInitialize(Handle *storage, RgnHandle blankRgn, GMParamBlockPtr params),
  64.     DoBlank(Handle storage, RgnHandle blankRgn, GMParamBlockPtr params),
  65.     DoDrawFrame(Handle storage, RgnHandle blankRgn, GMParamBlockPtr params),
  66.     DoClose(Handle storage, RgnHandle blankRgn, GMParamBlockPtr params),
  67.     DoSelected(Handle storage, RgnHandle blankRgn, GMParamBlockPtr params),
  68.     DoSetUp(RgnHandle blankRgn, short message, GMParamBlockPtr params);
  69. #endif
  70.  
  71.  
  72. /* entry point into graphics module */
  73.  
  74. pascal OSErr 
  75. main(Handle *storage, RgnHandle blankRgn, short message, GMParamBlockPtr params)
  76. /* storage allocated by graphics module. */
  77. /* region to do all drawing in. */
  78. /* the action to take */
  79. /* parameters & services for controlling graphics module */
  80. {
  81.     OSErr err=noErr;
  82.  
  83. #ifdef __MWERKS__
  84.     long oldA4=SetCurrentA4();
  85. #endif
  86. #ifdef THINK_C    
  87.     /* set up globals for strings etc. only for THINK C */
  88.     OpenGlobals();
  89. #endif    
  90.     /* dispatch message to appropriate routine. */
  91.     switch(message) {
  92.         case Initialize:
  93.             err=DoInitialize(storage, blankRgn, params);
  94.             break;
  95.         case Close:
  96.             err=DoClose(*storage, blankRgn, params);
  97.             break;
  98.         case Blank:
  99.             err=DoBlank(*storage, blankRgn, params);
  100.             break;
  101.         case DrawFrame:
  102.             err=DoDrawFrame(*storage, blankRgn, params);        
  103.             break;
  104.         
  105.         /*    Bouncing Ball does not handle the next two messages.    */
  106.         
  107.         case ModuleSelected:
  108.             /*err=DoSelected(*storage, blankRgn, params);*/
  109.             break;
  110.         case DoAbout:
  111.             /*err=DoAbout(*storage, blankRgn, params);*/
  112.             break;
  113.  
  114.         default: /* user may have hit a button */
  115.             if(message>=ButtonMessage) {
  116.                 /* handle the button */
  117.                 err=DoSetUp(blankRgn, message, params);
  118.             }  /* end if */
  119.             break;
  120.     } /* end switch */
  121. #ifdef THINK_C        
  122.     CloseGlobals();
  123. #endif    
  124. #ifdef __MWERKS__
  125.     SetA4(oldA4);
  126. #endif
  127.     return err;
  128. }
  129.